package jp.reflexworks.invoice.model;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class InvoiceBase {

	Logger logger = Logger.getLogger(this.getClass().getName());

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;
 
	@Persistent
	private long invoiceId;

	@Persistent
	private long orderId;

	@Persistent(mappedBy = "invoiceBase")  
	public List<Invoice> invoiceList;
	

	public Key getKey() {
		return key;
	}

	public void setKey(Key key) {
		this.key = key;
	}

	public long getOrderId() {
		return orderId;
	}

	public void setOrderId(long orderId) {
		this.orderId = orderId;
	}

	public long getInvoiceId() {
		return invoiceId;
	}

	public void setInvoiceId(long invoiceId) {
		this.invoiceId = invoiceId;
	}

	public List<Invoice> getInvoiceList() {
		return invoiceList;
	}

	public void setInvoiceList(List<Invoice> invoiceList) {
		this.invoiceList = invoiceList;
	}



	public void addInvoice(Invoice invoice) {
		if (invoiceList==null) {
			setInvoiceList(new ArrayList<Invoice>());  
		}
		
		List<Invoice> invoiceList = getInvoiceList();
		invoiceList.add(invoice); 
		setInvoiceList(invoiceList);
	}
	
	
}
